package com.czkj.hwz.decorate.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czkj.hwz.decorate.R;
import com.czkj.hwz.decorate.base.HttpUrl;
import com.czkj.hwz.decorate.bean.Worker;
import com.czkj.hwz.decorate.bean.WorkerType;
import com.czkj.hwz.decorate.bean1.ExamineEnterprise;
import com.czkj.hwz.decorate.bean1.User;
import com.king.base.adapter.ViewHolderAdapter;
import com.king.base.adapter.holder.ViewHolder;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：lxm on 2017/10/31 19:23
 * 邮箱：18014168291@189.cn
 * 才智科技
 */
public class WorkerItemAdapter extends ViewHolderAdapter<Worker> {
    private List<Worker> workerList;
    private List<ExamineEnterprise> examineEnterpriseList;
    private List<User> userList;
    private FinalBitmap fb;
    public WorkerItemAdapter(Context context, List<Worker> listData, List<ExamineEnterprise> examineEnterpriseList, List<User> userList) {
        super(context, listData);
        this.workerList=listData;
        this.examineEnterpriseList=examineEnterpriseList;
        this.userList=userList;
        if (fb==null) {
            fb=FinalBitmap.create(context);
            fb.configBitmapMaxHeight(150);
            fb.configBitmapMaxWidth(150);
        }
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, Worker worker, int position, ViewGroup parent) {
        return inflate(R.layout.worker_search_item,parent,false);
    }

    @Override
    public void bindViewDatas(ViewHolder holder, Worker worker, int position) {
        holder.setText(R.id.name,worker.getName());
        ImageView view = holder.getView(R.id.iv);
        LinearLayout ll=holder.getView(R.id.workers_ll);
        ArrayList<WorkerType> workerTypes= (ArrayList<WorkerType>) worker.getWorkerTypeList();
        fb.display(view, HttpUrl.BASE_URL+worker.getPhoto());
        ll.removeAllViews();
        for (int i=0;i<workerTypes.size();i++) {
            TextView tv=new TextView(getContext());
            LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
            tv.setLayoutParams(layoutParams);
            if (i==0) {
            }else {
                tv.setPadding(15,0,0,0);
            }
            tv.setText(workerTypes.get(i).getName());
            ll.addView(tv);
        }
        holder.setText(R.id.operation_center_tv,examineEnterpriseList.get(position).getName());
    }
}
